package com.gsmdata;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 */
public class GsmDataInputFormat extends InputFormat<NullWritable, Text> {
    @Override
    public List<InputSplit> getSplits(JobContext jobContext) {
        int splitNumber = Integer.parseInt(jobContext.getConfiguration().get("data.split_number"));
        int dataNumber = Integer.parseInt(jobContext.getConfiguration().get("data.data_number"));
        List<InputSplit> results = new ArrayList<InputSplit>();
        for (int i = 0; i < splitNumber; i++) {
            results.add(new GsmDataInputSplit(dataNumber));
        }
        return results;
    }

    @Override
    public RecordReader<NullWritable, Text> createRecordReader(InputSplit inputSplit, TaskAttemptContext taskAttemptContext) throws IOException, InterruptedException {
        return new GsmDataRecordReader();
    }
}
